#include "IOServer.h"

void IOPoint::init()
{
    // Overriden
}

void IOPoint::update()
{
    // Overriden
}

void IOPoint::setUri(std::string name)
{
    this->getValueUri = "/get_" + name;
    this->setValueUri = "/set_" + name;
    this->getOverrideUri = "/get_override_" + name;
    this->setOverrideUri = "/set_override_" + name;
}

void IOPoint::setDigital(uint8_t cmd)
{
    switch (ioType)
    {
        case DI:
            state = manual ? state : cmd;
            return;
            
        case DO:
            if (!manual)
            {
                state = cmd;
                if (mode != WEB_IO_LOGIC)
                {
                    digitalWrite(pin, state);
                }
            }
            return;
            
        default:
            return;
    }
}

void IOPoint::setAnalog(int cmd)
{
    switch (ioType)
    {
        case AI:
            value = manual ? value : cmd;
            return;
        
        case AO:
            if (!manual)
            {
                value = cmd;
                if (mode != WEB_IO_LOGIC)
                {
                    analogWrite(pin, value);
                }
            }
            return;
            
        default:
            return;
    }
}

bool IOPoint::getDigital()
{
    return state;
}

int IOPoint::getAnalog()
{
    return value;
}